package com.test.service.impl;

import java.util.UUID;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.test.common.PingYinUtil;
import com.test.dao.UserDao;
import com.test.model.UserModel;
import com.test.service.IUserService;

import net.sourceforge.pinyin4j.PinyinHelper;
import net.sourceforge.pinyin4j.format.HanyuPinyinCaseType;
import net.sourceforge.pinyin4j.format.HanyuPinyinOutputFormat;
import net.sourceforge.pinyin4j.format.HanyuPinyinToneType;
import net.sourceforge.pinyin4j.format.HanyuPinyinVCharType;
import net.sourceforge.pinyin4j.format.exception.BadHanyuPinyinOutputFormatCombination;
@Service
public class UserServiceImpl implements IUserService {
	@Resource
	private UserDao userDao;
	@Override
	public void insertOrUpdate(UserModel userModel) {
			userModel.setAccount(PingYinUtil.getPingYin(userModel.getName()));
			UserModel model = userDao.getUserByAccount(userModel.getAccount());
			userModel.setId(UUID.randomUUID().toString().replace("-", ""));
			userModel.setPassword(new StringBuffer(userModel.getAccount()).reverse().toString());
			if(model==null){
				userDao.add(userModel);
			}else {
				userDao.update(userModel);
			}
	}

}


